package jdk8的特性.使用流来收集数据.复杂分组;

import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.groupingBy;

/**
 * @author idea
 * @data 2018/9/16
 */
public class Test {

    public static void main(String[] args) {
        List<Food> foodList=MockFoodList.mockFoodList();
        Map<String,Map<String,List<Food>>> map=
                foodList.stream().collect(
                        groupingBy(Food::getType,
                                groupingBy(food->{
                                    if(food.getCaloricLevel()<200) return "低热量";
                                    else if(food.getCaloricLevel()<500) return "中等热闹";
                                    else return "高等热量";
                                }))
                );
        for (String s : map.keySet()) {
            System.out.println(s+":"+map.get(s).toString());
        }
    }
}
